package com.rd.p2p.app.account;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.AccountBankService;
import com.qdlc.p2p.biz.service.AccountCashService;
import com.qdlc.p2p.biz.service.AccountService;
import com.qdlc.p2p.biz.service.DictService;
import com.qdlc.p2p.biz.service.UserIdentifyService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dto.AccountBank;
import com.qdlc.p2p.dal.dto.AccountCash;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.AccountCashModel;

/**
 * 提现
 * 
 * @author xx
 * @version 2.0
 * @since 2014年3月14日
 */
public class AppCashAction extends BaseAction<AccountCashModel> implements ModelDriven<AccountCashModel> {

	@Resource
	private AccountBankService accountBankService;
	@Resource
	private AccountCashService accountCashService;
	private User user;

	private Map<String, Object> data;

	/**
	 * 是否已经绑定银行卡
	 * 
	 * @return
	 */
	@Action(value = "/app/user/checkBank")
	public void checkBank() throws Exception {
		data = new HashMap<String, Object>();
		user = getSessionUser();
		boolean hasBind = false ;
		if (user == null) {
			printWebResCodeAndMsgResult("-1","用户尚未登录!");
			return;
		}
		List<AccountBank> bankList = accountBankService.list(user.getUserId());
		if(bankList!=null&&bankList.size()>0){
		    for (AccountBank accountBank : bankList) {
                if(StringUtils.isNotEmpty(accountBank.getMobilephone())){
                    hasBind = true ;
                    break;
                }
            }
		}
		if(hasBind){
			printWebResCodeAndMsgResult("1","已绑定银行卡");
		}
		else{
			printWebResCodeAndMsgResult("0", "未绑定银行卡");
		}
		return;
	}


	/**
	 * 提现记录 ajax数据接口
	 * 
	 * @return
	 */
	@Action("/app/user/logList")
	public void logList() throws Exception {
		user = getSessionUser();
		long userId = user.getUserId();
		String status = paramString("status");
		if (StringUtil.isBlank(status)) {
			model.setStatus(99);
		}
		PageDataList<AccountCashModel> pageDateList = accountCashService.list(userId, model.getPage(), model);
		AccountCash model  = accountCashService.getCashMessage(userId);
		data = new HashMap<String, Object>();
		data.put("data", pageDateList);
		data.put("model", model);
		data.put("resCode", "1");
		printWebJson(getStringOfJpaObj(data));
	}

}
